<?php
/**
 * email.php
 *
 * Author: netman
 * DateTime:  2023/7/17 17:24
 */

class Listener_Order_Created_Email extends Listener_Base
{


    public function handle($args)
    {
        $self       = new self();
        $self->args = $args;
        //判断队列是否开启,如果开启则把任务推送到队列
        if ($self->queue_status) {
            //推送到队列执行
            Queue::in('default', Listener_Order_Created_Email::class, $args);
        } else {
            $self->perform();
        }
    }

    public function perform()
    {
        $order = $this->args;
        switch ($order['need_confirm']) {
            case 2://支付前确认
                $type = St_NoticeCommon::PRODUCT_ORDER_UNPROCESSING_MSGTAG;
                break;
            case 0:
            case 1:
            default:
                $type = St_NoticeCommon::PRODUCT_ORDER_PROCESSING_MSGTAG;
                break;
        }
        //用户通知信息
        $result = St_EmailService::send_product_order_email($type, $order);
        St_Log::write('邮件通知', array('type' => $type, 'ordersn' => $order['ordersn'], 'result' => $result), 'event/order_created/log');
    }

}